package com.autonavi.collapse.task.model;

public class TaskResult {

    public static TaskResult EMPTY = new TaskResult();

    private TaskResultStatus status;

    private TaskConfig task;

    private String message;

    public TaskResult() {
    }

    public TaskResult(TaskResultStatus status, TaskConfig task, String message) {
        this.status = status;
        this.task = task;
        this.message = message;
    }

    public static TaskResult success(TaskConfig task){
        return new TaskResult(TaskResultStatus.SUCCESS, task, null);
    }

    public static TaskResult success(TaskConfig task, String message){
        return new TaskResult(TaskResultStatus.SUCCESS, task, message);
    }

    public static TaskResult interrupt(TaskConfig task){
        return new TaskResult(TaskResultStatus.INTERRUPTED, task, null);
    }

    public static TaskResult fail(TaskConfig task, String message){
        return new TaskResult(TaskResultStatus.FAIL, task, message);
    }

    public static TaskResult fail(TaskConfig task, Exception e){
        return new TaskResult(TaskResultStatus.FAIL, task, String.format("%s: %s", e.getClass().getName(), e.getMessage()));
    }

    public static TaskResult error(TaskConfig task, String message){
        return new TaskResult(TaskResultStatus.ERROR, task, message);
    }

    public static TaskResult error(TaskConfig task, Exception e){
        return new TaskResult(TaskResultStatus.ERROR, task, String.format("%s: %s", e.getClass().getName(), e.getMessage()));
    }

    public String toString() {
        return status.name();
    }

    public TaskResultStatus getStatus() {
        return status;
    }

    public TaskConfig getTask() {
        return task;
    }

    public String getMessage() {
        return message;
    }

}
